<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'
import { useTokenStore } from '@/stores/token'
import { Search, ShoppingCart, List, User,SwitchButton,ShoppingBag } from '@element-plus/icons-vue'

const router = useRouter()
const tokenStore = useTokenStore()

const goToHome = () => {
  router.push('/student/home')
}

const handleLogout = () => {
  tokenStore.removeToken()
  router.push('/login')
  ElMessage.success('退出登录成功')
}


const goToProfile = () => {
  router.push('/student/profile')
}
</script>

<template>
  <div class="user-layout">
    <header class="header">
      <div class="logo" @click="goToHome">
        <img src="@/assets/logo.png" alt="Logo" />
        <span class="title">智慧宿舍</span>
      </div>
      
      <div class="user-actions">
        <div class="nav-links">
        </div>
        <el-dropdown trigger="hover">
          <span class="user-info">
            <el-icon><User /></el-icon>
            {{ tokenStore.studentInfo.username }}
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="goToProfile">
                <el-icon><User /></el-icon>
                <span>个人信息</span>
              </el-dropdown-item>
              <el-dropdown-item @click="handleLogout" divided>
                <el-icon><SwitchButton /></el-icon>
                <span>退出登录</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </header>

    <main class="main-content">
      <router-view></router-view>
    </main>

    <footer class="footer">
      <span>CreateBy6组@2025</span>
    </footer>
  </div>
</template>

<style scoped>
.user-layout {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.header {
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  cursor: pointer;
}

.logo img {
  height: 40px;
  margin-right: 10px;
}

.title {
  font-size: 1.5rem;
  font-weight: bold;
  color: #333;
}
.user-info {
  display: flex;
  align-items: center;
  cursor: pointer;
  color: #333;
  gap: 8px;
}

.user-actions {
  display: flex;
  align-items: center;
  gap: 2rem;

  .nav-links {
    display: flex;
    gap: 1.5rem;
  }

  .nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: #606266;
    transition: color 0.3s;

    &:hover {
      color: var(--el-color-primary);
    }

    .el-icon {
      font-size: 1.2rem;
    }
  }

  .user-avatar {
    cursor: pointer;
    transition: transform 0.3s;

    &:hover {
      transform: scale(1.05);
    }
  }
}

.main-content {
  flex: 1;
  padding: 2rem;
  background-color: #f5f7fa;
  margin-bottom: 60px;
}

.footer {
  height: 60px;
  background-color: #fff;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  color: #606266;
  font-size: 14px;
}

@media (max-width: 768px) {
  .header {
    flex-direction: column;
    padding: 1rem;
    gap: 1rem;
  }

  .search-box {
    width: 100%;
    margin: 1rem 0;
  }

  .user-actions {
    width: 100%;
    justify-content: space-between;
  }
}
</style>